#include "form.h"
#include "ui_form.h"
#include <QMessageBox>
#include <QWidget>
#include <QKeyEvent>
form::form(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::form)
{
    ui->setupUi(this);
    this->setAutoFillBackground(true);//
        QPalette pa = this->palette();
        pa.setBrush(QPalette::Window,QBrush(QPixmap("9.jpg").scaled(this->size(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation)));
        this->setPalette(pa);
}

form::~form()
{
    delete ui;
}

void form::on_pushButton_clicked()
{
    emit send_msg("1");
    ui->lineEdit->clear();
    ui->lineEdit_2->clear();
    ui->lineEdit_3->clear();
    ui->label->clear();

    this->hide();
}

void form::on_pushButton_2_clicked()
{
    float op1 =ui->lineEdit->text().toFloat();
    float op2 =ui->lineEdit_2->text().toFloat();
    float op3 =ui->lineEdit_3->text().toFloat();
    if(ui->comboBox->currentText() == "+")
    {
        op3 = op1 + op2;
    }
    if(ui->comboBox->currentText() == "-")
    {
        op3 = op1 - op2;
    }
    if(ui->comboBox->currentText() == "*")
    {
        op3 = op1 * op2;
    }
    if(ui->comboBox->currentText() == "/")
    {
        if(op2 == 0)
        {
            QMessageBox::warning(this,"警告","除数不能为零");
            ui->lineEdit_2->clear();
            return;
        }
        op3 = op1 / op2;
    }
    QString adds = QString("%1").arg(op1) +ui->comboBox->currentText()+ QString("%1").arg(op2) +" = "+QString("%1").arg(op3);
    ui->label->setText(adds);
    ui->lineEdit_3->setText(QString("%1").arg(op3));
    ui->textBrowser->setText(adds);


}

void form::on_pushButton_3_clicked()
{
     ui->lineEdit->clear();
     ui->lineEdit_2->clear();
     ui->lineEdit_3->clear();
}
/*void QWidget::keyPressEvent(QKeyEvent *event)
{
    if(event->key() == Qt::Key_Enter  || event->key() == Qt::Key_Return)
    {
        this->focusNextChild();
    }
}*/
